<?php 
include_once('connection/connection.php');
include('header.php');
include('menu.php');
include('config.php');
$block=$_SESSION['form_id'];
$district=$_SESSION['district'];
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Sanitry Analysis</title>
<style type="text/css">

.style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px; color:#000000}
.style11 {font-size: 9px}

</style>
</head>
<body>
<?php
 $distId= $district;
 $blockId=$block;

	function getName($colName,$id)
        {
	$sqlgetName="select distinct ".$colName."_name from tbl_lookup_location where ".$colName."_id=".$id;
	$querygetName=mysql_query($sqlgetName);
	$rowgetName=mysql_fetch_row($querygetName);
	return $rowgetName[0];
        }
	////////////////////////////
	 if(($distId == 391) || ($distId == 393) || ($distId == 396) || ($distId == 400) || ($distId == 405) || ($distId == 411) || ($distId == 414))
	  {	
		
		function risk_analysis($distid,$blockid,$habit,$src,$q1)
         {
	$sql="SELECT  count(distinct loc_id) FROM tbl_dtls_q3_last detail,tbl_dtls_q3_loc loc where loc.id=detail.loc_id and detail.id=(select max(id) from tbl_dtls_q3_last where habit_name='$habit') and loc.district_id='$distid' and loc.block_id='$blockid' and detail.habit_name='$habit' and detail.source_type='$src' and detail.$q1='YES'";
	$query=mysql_query($sql);
	$row=mysql_fetch_row($query);
	return $row[0];
         }
	 }

////////////////////////////////////////////
    $sqlgetParameter="SELECT block_id,panchayat_id,habitation_name,location,source_type,functional_status,para_ph,para_tds,para_cl,para_f,para_no3 FROM tbl_dtls_q3_water_source_detail detail,tbl_dtls_q3_loc loc where loc.id=detail.loc_id and loc.district_id='$distId' and loc.block_id='$blockId'";
	$querygetParameter=mysql_query($sqlgetParameter);
	//$rowgetParameter=mysql_fetch_array($querygetParameter);


         
//Select Data from lookup location table village wise
/*$sqlReport = "SELECT  distinct detail.source_type,detail.functional_status,detail.bact FROM tbl_dtls_q3_water_source_detail detail,tbl_dtls_q3_loc loc WHERE loc.id=detail.loc_id and loc.district_id='$distId' and loc.block_id='$blockId' order by detail.source_type";
$queryReport = mysql_query($sqlReport);*/



//find lpcd for district
/*if(($distId == 389) || ($distId ==390) || ($distId == 391) || ($distId ==392) || ($distId == 401) || ($distId == 402) || ($distId == 403) || ($distId == 404) || ($distId == 405) || ($distId == 406) || ($distId == 416))
{
	$lpcd=70;
}
else
{
	$lpcd=40;
}*/

?>
<table border="0" width="1104" cellspacing="0" cellpadding="0">
	<tr>
		<td width="1104" height="26" bgcolor="#E9E9E9">
		<p align="center"><span style="font-size: 9pt; font-weight: 700">
	  <font face="Verdana" color="#224568">Sanitary Risk Analysis</font></span></td>
	</tr>
	
	<tr>
	  <td height="14"><div align="center">
	  <?php
	 // if($rowgetParameter == 0)
      //  {
      //  echo"<font color='red'><h4>There is no data</h1></font>";
      //  }
       ?>  
 </div></td>
  </tr>
	
	<tr>
	  <td height="111"><table border="1" width="1104" cellspacing="0" cellpadding="0" height="64" bordercolor="#FFFFFF" style="border: 1px solid #BBD1E8" bgcolor="#F9F9F9">
        <tr bgcolor="#C5D8EB">
          <td width="127" height="40" rowspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Block</font></td>
          <td width="108" rowspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">GramPanchayat</font></td>
          <td width="176" rowspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Habitation</font></td>
          <td width="121" rowspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Location</font></td>
          <td width="144" rowspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Source Type</font></td>
          <td width="100" rowspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Functional Status</font></td>
          <td height="16" colspan="5" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Water Quality</font></td>
          <td width="65" rowspan="2" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">Sanitry Risk</font></td>
        </tr>
        <tr bgcolor="#C5D8EB">
          <td width="53" height="20" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">PH</font></td>
          <td width="55" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">TDS</font></td>
          <td width="46" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">CL</font></td>
          <td width="46" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">F</font></td>
          <td width="37" align="center"><font face="Verdana" style="font-size: 9.5pt" color="#000000">NO<sub>3</sub></font></td>
        </tr>
        
            <?php
			while($rowgetParameter=mysql_fetch_array($querygetParameter)) 
			{
			$block=$rowgetParameter['block_id'];
			$panchayat=$rowgetParameter['panchayat_id'];
			$habitation=$rowgetParameter['habitation_name'];
			$location=$rowgetParameter['location'];
			$source=$rowgetParameter['source_type'];
			$status=$rowgetParameter['functional_status'];
			$ph=$rowgetParameter['para_ph'];
			$tds=$rowgetParameter['para_tds'];
			$cl=$rowgetParameter['para_cl'];
			$f=$rowgetParameter['para_f'];
			$no3=$rowgetParameter['para_no3'];
			$block_name=getName('block',$block);
			$panchayat_name=getName('panchayat',$panchayat);
			$TotalRisk=substr($source, 0, 2);
			////////////////////////////////////////
		 $ques1=risk_analysis($distId,$blockId,$habitation,$source,risk_analysis_q1);
		 $ques1+=risk_analysis($distId,$blockId,$habitation,$source,risk_analysis_q2);
		 $ques1+=risk_analysis($distId,$blockId,$habitation,$source,risk_analysis_q3);
		 $ques1+=risk_analysis($distId,$blockId,$habitation,$source,risk_analysis_q4);
		 $ques1+=risk_analysis($distId,$blockId,$habitation,$source,risk_analysis_q5);
		 $ques1+=risk_analysis($distId,$blockId,$habitation,$source,risk_analysis_q6);
		 $ques1+=risk_analysis($distId,$blockId,$habitation,$source,risk_analysis_q7);
		 $ques1+=risk_analysis($distId,$blockId,$habitation,$source,risk_analysis_q8);
		 $ques1+=risk_analysis($distId,$blockId,$habitation,$source,risk_analysis_q9);
		 //$ques1+=risk_analysis($distId,$blockId,$habitation,$source,risk_analysis_q10);
		 //$ques1+=risk_analysis($distId,$blockId,$habitation,$source,risk_analysis_q11);
			
			
			///////////////////////////////////////
			if($TotalRisk == 'Hp')
			{
			$denominator=9;
			}elseif($TotalRisk == 'TW' or $TotalRisk == 'Ra')
			  {
			    $denominator=10;
			  }elseif($TotalRisk == 'DW')
			    {
			     $denominator=11;
			    }
			?>
		
		<tr>
          <td height="26" align="center"><span class="style10"><?php echo $block_name;?></span></td>
          <td align="center"><span class="style10"><?php echo $panchayat_name;?></span></td>
          <td align="center"><span class="style10"><?php echo $habitation;?></span></td>
          <td align="center"><span class="style10"><?php echo $location;?></span></td>
          <td align="center"><span class="style10"><?php echo $source;?></span></td>
          <td align="center"><span class="style10"><?php echo $status;?></span></td>
          <td align="center"><span class="style10"><?php echo $ph;?></span></td>
          <td align="center"><span class="style10"><?php echo $tds;?></span></td>
          <td align="center"><span class="style10"><?php echo $cl;?></span></td>
          <td align="center"><span class="style10"><?php echo $f;?></span></td>
          <td align="center"><span class="style10"><?php echo $no3;?></span></td>
          <td align="center"><span class="style10">
		  <?php 
		  if($status == 'NF')
		  {
		  echo " ";
		  }else{
		  echo $ques1."/".$denominator;
		 }
		  ?>
		  </span></td>
        </tr>
        <?php } ?>
      </table></td>
	</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>